package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/03/13 17:51
 **/
public class Day3_13_Num2383 {
    class Solution {
        public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
            int dayCount = 0;
            int n = energy.length;
            for(int i = 0; i < n; ++i) {
                if(initialEnergy > energy[i]) {
                    initialEnergy -= energy[i];
                }else {
                    int diff = energy[i] - initialEnergy + 1;
                    dayCount += diff;
                    initialEnergy = 1;
                }

                if(initialExperience > experience[i]) {
                    initialExperience += experience[i];
                }else {
                    int diff = experience[i] - initialExperience + 1;
                    dayCount += diff;
                    initialExperience += diff;
                    initialExperience += experience[i];
                }
            }
            return dayCount;
        }
    }
}